/**
 * Copyright (c) 2018, wuyy All rights reserved.
 * wuyy 专有/保密源代码,未经许可禁止任何人通过任何渠道使用、修改源代码.
 * QQ:16349023
 * 项目名称 : com.wy2.eclipse.tool.ui
 * @version V1.0
 */
package com.wy2.eclipse.tool.ui.editors;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import com.wy2.generator.database.entity.DatabaseColumn;
import com.wy2.generator.database.entity.DatabaseTable;

/**
 * 数据表内容提供者
 * @author wuyy<16349023@qq.com>
 * @date 2018年1月21日上午9:35:45
 * 
 */
public class TableContentProvider extends ArrayContentProvider implements ITreeContentProvider {

    /** 
     * @param parentElement
     * @return 
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
     */
    @Override
    public Object[] getChildren(Object parentElement) {
        if(parentElement instanceof DatabaseTable) {
            DatabaseTable table=(DatabaseTable)parentElement;
            return table.getColumns().toArray(new DatabaseColumn[0]);
        }
        return null;
    }

    /** 
     * @param element
     * @return 
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
     */
    @Override
    public Object getParent(Object element) {
        if(element instanceof DatabaseColumn) {
            DatabaseColumn column=(DatabaseColumn)element;
            return column.getTable();
        }
        return null;
    }

    /** 
     * @param element
     * @return 
     * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
     */
    @Override
    public boolean hasChildren(Object element) {
        if(element instanceof DatabaseTable) {
            DatabaseTable table=(DatabaseTable)element;
            return table.getColumns().size()>0;
        }
        return false;
    }

}
